package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.SetMeal;
import com.itheima.reggie.service.DishService;
import com.itheima.reggie.service.SetMealService;
import com.itheima.reggie.vo.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

public class SetMealController {

    @Autowired
    private SetMealService setMealService;

    @Autowired
    private DishService dishService;

    /**
     * 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/setmeal/page")
    public ResultInfo findByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize, String name) {
        Page<SetMeal> page = setMealService.findByPage(pageNum, pageSize, name);
        return ResultInfo.success(page);
    }

    /**
     * 新增菜品
     *
     * @param setMeal
     * @return
     */
    @PostMapping("/setmeal")
    public ResultInfo add(@RequestBody SetMeal setMeal) {
        setMealService.add(setMeal);
        return ResultInfo.success(null);
    }


    /**
     * 单 批  启售 停售
     *
     * @param status
     * @param myUtil
     * @return
     */
    //todo  接成对象 为啥不加   @RequestBody    什么时候用
    @PostMapping("/setmeal/status/{status}")
    public ResultInfo stopAndStart(@PathVariable("status") Integer status, MyUtil myUtil) {
        setMealService.stopAndStart(status, myUtil);
        return ResultInfo.success(null);
    }


    /**
     * 删除  单 批
     *
     * @param myUtil
     * @return
     */
    @DeleteMapping("/setmeal")
    public ResultInfo delete(MyUtil myUtil) {
        setMealService.deleteByIds(myUtil.getIds());
        return ResultInfo.success(null);
    }

    //回显套餐信息
    @GetMapping("/setmeal/{id}")
    public ResultInfo findById(@PathVariable("id") Long id){
        SetMeal setMeal = setMealService.findById(id);
        return ResultInfo.success(setMeal);
    }


    @PutMapping("/setmeal")
    public ResultInfo update(@RequestBody SetMeal setMeal) {
        setMealService.update(setMeal);
        return ResultInfo.success(null);
    }


}
